import type { Column } from "@/components/CrudPage/type";

import { deleteKnoDoc, type KnoDoc } from "@/views/domain/knowledge/api/knoDoc";
import { messager } from "@/utils/message";

export function useKnoDocProvider() {
  // 列配置
  const columns: Column[] = [
    {
      label: "",
      prop: "id",
      slot: "id",
      search: true,
      create: true,
      edit: true,
      colProps: { span: 12 }
      // cellRenderer: ({ row }) => (<div />) // render in table
      // renderField: (value, onChange) => (<div/>) // render in form
    },
    {
      label: "",
      prop: "title",
      slot: "title",
      search: true,
      create: true,
      edit: true,
      colProps: { span: 12 }
      // cellRenderer: ({ row }) => (<div />) // render in table
      // renderField: (value, onChange) => (<div/>) // render in form
    },
    {
      label: "",
      prop: "desc",
      slot: "desc",
      search: true,
      create: true,
      edit: true,
      colProps: { span: 12 }
      // cellRenderer: ({ row }) => (<div />) // render in table
      // renderField: (value, onChange) => (<div/>) // render in form
    },
    {
      label: "",
      prop: "vector",
      slot: "vector",
      search: true,
      create: true,
      edit: true,
      colProps: { span: 12 }
      // cellRenderer: ({ row }) => (<div />) // render in table
      // renderField: (value, onChange) => (<div/>) // render in form
    },
    {
      label: "",
      prop: "refId",
      slot: "refId",
      search: true,
      create: true,
      edit: true,
      colProps: { span: 12 }
      // cellRenderer: ({ row }) => (<div />) // render in table
      // renderField: (value, onChange) => (<div/>) // render in form
    },
    {
      label: "",
      prop: "sourcePath",
      slot: "sourcePath",
      search: true,
      create: true,
      edit: true,
      colProps: { span: 12 }
      // cellRenderer: ({ row }) => (<div />) // render in table
      // renderField: (value, onChange) => (<div/>) // render in form
    },
    {
      label: "",
      prop: "fromModel",
      slot: "fromModel",
      search: true,
      create: true,
      edit: true,
      colProps: { span: 12 }
      // cellRenderer: ({ row }) => (<div />) // render in table
      // renderField: (value, onChange) => (<div/>) // render in form
    },
    {
      label: "",
      prop: "status",
      slot: "status",
      search: true,
      create: true,
      edit: true,
      colProps: { span: 12 }
      // cellRenderer: ({ row }) => (<div />) // render in table
      // renderField: (value, onChange) => (<div/>) // render in form
    },
    {
      label: "",
      prop: "order",
      slot: "order",
      search: true,
      create: true,
      edit: true,
      colProps: { span: 12 }
      // cellRenderer: ({ row }) => (<div />) // render in table
      // renderField: (value, onChange) => (<div/>) // render in form
    },
    {
      label: "",
      prop: "createdBy",
      slot: "createdBy",
      search: true,
      create: true,
      edit: true,
      colProps: { span: 12 }
      // cellRenderer: ({ row }) => (<div />) // render in table
      // renderField: (value, onChange) => (<div/>) // render in form
    },
    {
      label: "",
      prop: "updatedBy",
      slot: "updatedBy",
      search: true,
      create: true,
      edit: true,
      colProps: { span: 12 }
      // cellRenderer: ({ row }) => (<div />) // render in table
      // renderField: (value, onChange) => (<div/>) // render in form
    },
    {
      label: "",
      prop: "deletedBy",
      slot: "deletedBy",
      search: true,
      create: true,
      edit: true,
      colProps: { span: 12 }
      // cellRenderer: ({ row }) => (<div />) // render in table
      // renderField: (value, onChange) => (<div/>) // render in form
    },
    {
      label: "",
      prop: "createdAt",
      slot: "createdAt",
      search: true,
      create: true,
      edit: true,
      colProps: { span: 12 }
      // cellRenderer: ({ row }) => (<div />) // render in table
      // renderField: (value, onChange) => (<div/>) // render in form
    },
    {
      label: "",
      prop: "updatedAt",
      slot: "updatedAt",
      search: true,
      create: true,
      edit: true,
      colProps: { span: 12 }
      // cellRenderer: ({ row }) => (<div />) // render in table
      // renderField: (value, onChange) => (<div/>) // render in form
    },
    {
      label: "",
      prop: "deletedAt",
      slot: "deletedAt",
      search: true,
      create: true,
      edit: true,
      colProps: { span: 12 }
      // cellRenderer: ({ row }) => (<div />) // render in table
      // renderField: (value, onChange) => (<div/>) // render in form
    },
    {
      label: "",
      prop: "tenantId",
      slot: "tenantId",
      search: true,
      create: true,
      edit: true,
      colProps: { span: 12 }
      // cellRenderer: ({ row }) => (<div />) // render in table
      // renderField: (value, onChange) => (<div/>) // render in form
    },
    {
      label: "操作",
      prop: "operation",
      slot: "operation"
    }
  ];

  // 删除row
  const deleteRow = (row: KnoDoc) => {
    deleteKnoDoc(row).then(({ ok, msg }) => {
      messager.alert(ok, msg);
    });
  };

  return {
    columns,
    deleteRow
  };
}
